<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class="app-container">
    <el-form id="mvcfm">
      <el-row>
        <el-col :span="7" :xs="24">
          <div class="form-unit">
            <span class="mvc-title-left"> 我的仪表盘 </span>
          </div>
          <div>
            <el-row>
              <el-col :span="24">
                <el-tree :data="s_firm" :highlight-current="true" class='mvctree' v-loading="treeloading" @node-click="handleNodeClick">
                  <span class="el-tree-node__label" slot-scope="{node,data}" v-html="data.__desc"></span>
                </el-tree>
              </el-col>
            </el-row>
          </div>
        </el-col>
        <el-col :span="16" :xs="24">
          <div class="form-unit">
            <a v-for="dict in s_outline" @click="handleNodeClick(dict)" type='primary'>{{dict.__desc}}></a>
          </div>
          <div class="form-unit">
            <span class="mvc-title-left"> 人员列表 </span>
          </div>
          <el-button @click="gotoPage('/oa/humanresources/InterviewAdoptList?'+vueparams+'')" type='primary' size="mini">面试录用</el-button>
          <el-button @click="gotoPage('/oa/humanresources/StaffAdd?'+vueparams+'')" type='success' size="mini"><i class='fa fa-plus'></i>增加员工</el-button>
          <el-table :data="pageList" v-loading="loading">
            <el-table-column label="#" align="center" type='index'>
            </el-table-column>
            <el-table-column label="操作" align="center" width='100' type=''>
              <template slot-scope="scope">
                <el-dropdown trigger="click">
                  <span class="el-dropdown-link">操作<i class="el-icon-arrow-down el-icon--right"></i></span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>
                      <el-link @click="d_person('&CMID='+scope.row.contact_id+'')">删除</el-link>
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-link @click="gotoPage('/oa/humanresources/StaffUp?CMID='+scope.row.contact_id+''+vueparams+'')">修改</el-link>
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-link @click="disable('&user_id='+scope.row.user_id+'')">禁用</el-link>
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-link @click="restore('&user_id='+scope.row.user_id+'')">启用</el-link>
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-link @click="gotoPage('/oa/humanresources/StaffDet?CMID='+scope.row.contact_id+''+vueparams+'')">查看明细</el-link>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </template>
            </el-table-column>
            <el-table-column label="编号" prop="contact_id">
            </el-table-column>
            <el-table-column label="人员名称" prop="contact_id">
              <template slot-scope="scope">
                <el-link @click="gotoPage('/oa/humanresources/StaffDet?CMID='+scope.row.contact_id+''+vueparams+'')" type='primary'>{{scope.row.contact_name}}</el-link>
              </template>
            </el-table-column>
            <el-table-column label="账号" prop="username">
            </el-table-column>
            <el-table-column label="岗位" prop="role">
            </el-table-column>
            <el-table-column label="状态" prop="enabled">
              <template slot-scope="scope">
                {{getValueName("禁用=0,启用=1",scope.row.enabled)}}
              </template>
            </el-table-column>
            <el-table-column label="上级领导" prop="person_name">
            </el-table-column>
            <el-table-column label="手机号码" prop="relation_cel">
            </el-table-column>
            <el-table-column label="Email" prop="relation_email">
            </el-table-column>
          </el-table>
          <pagination v-show="total>0" :total="total" :limit.sync="pageSize" @pagination="getPage" />
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
  import request from '@/utils/request'
  export default {
    name: 'StaffList',
    components: {},
    props: ['popparams'],
    data() {
      return {
        vueparams: this.getVUEParams(""),
        search: {
          CMID1: null,
        },
        s_user: [],
        treeloading: true,
        s_firm: [],
        s_outline: [],
        loading: true,
        pageList: [],
        pageSize: 10,
        total: null,
        rules: {}
      }
    },
    created() {
      this.getData();
      this.getPage(1);
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/oa/humanresources/EmployeeAction/staffList?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
          this["s_firm"] = this.loadTreeTable(this["s_firm"], "firm_id", "firm_higher");
          this.treeloading = false;
        })
      },
      d_person(_params) {
        request({
          method: 'post',
          url: '/xcapi/VUEAction/oa/humanresources/EmployeeAction/d_person?' + _params + this.vueparams,
          data: this.postData()
        }).then(data => {
          this.$router.replace("/redirect" + this.$route.fullPath);
          this.msgSuccess(data.msg);
        })
      },
      disable(_params) {
        request({
          method: 'post',
          url: '/xcapi/VUEAction/oa/humanresources/EmployeeAction/disable?' + _params + this.vueparams,
          data: this.postData()
        }).then(data => {
          this.$router.replace("/redirect" + this.$route.fullPath);
          this.msgSuccess(data.msg);
        })
      },
      restore(_params) {
        request({
          method: 'post',
          url: '/xcapi/VUEAction/oa/humanresources/EmployeeAction/restore?' + _params + this.vueparams,
          data: this.postData()
        }).then(data => {
          this.$router.replace("/redirect" + this.$route.fullPath);
          this.msgSuccess(data.msg);
        })
      },
      getPage(page) {
        this.loading = true;
        this.search.pageNo = page.page || page;
        this.search.pageSize = page.limit || 10;
        request({
          method: 'get',
          url: '/xcapi/VUEAction/oa/humanresources/EmployeeAction/s_user?' + this.vueparams,
          params: this.search
        }).then(data => {
          this.loading = false;
          this.pageList = data.rows;
          this.total = data.total;
        })
      },
      handleNodeClick(data) {
        this.search.CMID1 = data.firm_id;
        this.handleOutline(data);
        this.getPage(1);
      },
      handleOutline(data) {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/oa/humanresources/EmployeeAction/s_outline?' + this.vueparams,
          params: this.search
        }).then(data => {
          this.s_outline = data.s_outline;
          this.s_outline = this.s_outline.reverse();
        })
      },
    },
  }
</script>
